﻿@model LanguageModel

@using Telerik.Web.Mvc.UI;
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("language-edit").Items(x =>
{
    x.Add().Text(T("Admin.Configuration.Languages.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
    x.Add().Text(T("Admin.Configuration.Languages.Stores").Text).Content(TabStores().ToHtmlString());

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "language-edit"));
})
@helper TabInfo()
{
    <script type="text/javascript">
        function toggleFlags() {
            $('#pnlAllFlags').toggle();
            if ($('#pnlAllFlags').css('display') == 'none') {
                $('#displayAllFlags').html('@T("Admin.Common.Show")');
            }
            else {
                $('#displayAllFlags').html('@T("Admin.Common.Hide")');
            }
        }
    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Name):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LanguageCulture):
            </td>
            <td class="adminData">
                 @{
                    var cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)
                        .OrderBy(x => x.EnglishName)
                        .Select(x => new SelectListItem()
                                         {
                                             Value = x.IetfLanguageTag,
                                             Text = string.Format("{0}. {1}", x.EnglishName, x.IetfLanguageTag)
                                         });
                }
                @Html.DropDownListFor(model => model.LanguageCulture, cultures)
                @Html.ValidationMessageFor(model => model.LanguageCulture)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.UniqueSeoCode):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.UniqueSeoCode)
                @Html.ValidationMessageFor(model => model.UniqueSeoCode)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.FlagImageFileName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.FlagImageFileName)
                @Html.ValidationMessageFor(model => model.FlagImageFileName)
                <br/>
                <a id="displayAllFlags" href="javascript:toggleFlags();">@T("Admin.Common.Show")</a>
                <div id="pnlAllFlags" style="display: none">
                    @foreach (var fileName in Model.FlagFileNames)
                    {
                        <img alt="" src="@Url.Content("~/Content/Images/flags/" + fileName)"/>
                        @fileName
                        <text>, </text>
                    }
                </div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Rtl):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Rtl)
                @Html.ValidationMessageFor(model => model.Rtl)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Published):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Published)
                @Html.ValidationMessageFor(model => model.Published)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.DisplayOrder):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.DisplayOrder)
                @Html.ValidationMessageFor(model => model.DisplayOrder)
            </td>
        </tr>
    </table>
}
@helper TabStores()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToStores)").click(toggleStoreMapping);

            toggleStoreMapping();
        });


        function toggleStoreMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToStores)').is(':checked')) {
                $('#pnl-available-stores').show();
            }
            else {
                $('#pnl-available-stores').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitedToStores):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToStores)
                @Html.ValidationMessageFor(model => model.LimitedToStores)
            </td>
        </tr>
        <tr id="pnl-available-stores">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AvailableStores):
            </td>
            <td class="adminData">
                @if (Model.AvailableStores != null && Model.AvailableStores.Count > 0)
                {
                    foreach (var store in Model.AvailableStores)
                    {
                    <div>
                        <input type="checkbox" name="SelectedStoreIds" value="@store.Id" checked="@(Model.SelectedStoreIds != null && Model.SelectedStoreIds.Contains(store.Id))" />@store.Name
                    </div>
                    }
                }
                else
                {
                    <div>No stores defined</div>
                }</td>
        </tr>
    </table>
}
